/** 
* Copyright (C) 2012-2018 ZEEI Inc.All Rights Reserved.
* 项目名称：pls
* 文件名称：PunishInfoGisServiceImpl.java
* 包  名  称：com.zeei.gis.service.imp
* 文件描述：TODO 请修改文件描述
* 创建日期：2018年1月19日下午1:39:32
* 
* 修改历史
* 1.0 jiangqingpeng 2018年1月19日下午1:39:32 创建文件
*
*/

package com.zeei.gis.service.imp;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zeei.common.utils.StringUtil;
import com.zeei.gis.dao.AreaCodeGisDao;
import com.zeei.gis.dao.PunishInfoGisVODao;
import com.zeei.gis.service.PunishInfoGisService;
import com.zeei.gis.vo.PunishInfoConditionGisVO;
import com.zeei.gis.vo.PunishInfoGisVO;

/**
 * @类型名称：PunishInfoGisServiceImpl
 * @类描述：TODO 违法企业管理
 * @功能描述：TODO 违法企业管理
 * @创建作者：jiangqingpeng
 */
@Service("punishInfoGisService")
public class PunishInfoGisServiceImpl implements PunishInfoGisService{
	
	@Autowired
	AreaCodeGisDao areaCodeGisDao;

	@Autowired
	PunishInfoGisVODao punishInfoGisVODao;
	
	/**
	 * queryPunishInfoByYear:TODO 按年份统计每个市企业次数
	 *
	 * @param punishInfoConditionGisVO
	 * @return List<PunishInfoGisVO>
	 */
	@Override
	public List<PunishInfoGisVO> queryPunishInfoByYear(PunishInfoConditionGisVO punishInfoConditionGisVO) {
		if (punishInfoConditionGisVO.getAreacode() != null && punishInfoConditionGisVO.getAreacode().length() != 0) {
			punishInfoConditionGisVO.setDisposeAreacode(punishInfoConditionGisVO.getAreacode().substring(0, 4));
		}
		if (punishInfoConditionGisVO.getYear() == null || punishInfoConditionGisVO.getYear().length() == 0) {
			punishInfoConditionGisVO.setYear(getDateOfYeaf());
		}
		List<PunishInfoGisVO> list = punishInfoGisVODao.queryPunishInfoByYear(punishInfoConditionGisVO);
		return list;
		
	}

	/**
	 * queryCompanyPunishInfo:TODO 查询每个区县下每个企业是否违法
	 *
	 * @param punishInfoConditionGisVO
	 * @return List<PunishInfoGisVO>
	 */
	@Override
	public List<PunishInfoGisVO> queryCompanyPunishInfo(PunishInfoConditionGisVO punishInfoConditionGisVO) {
		if (punishInfoConditionGisVO.getAreacode() != null && !punishInfoConditionGisVO.getAreacode().isEmpty()) {
			punishInfoConditionGisVO.setDisposeAreacode(punishInfoConditionGisVO.getAreacode().substring(0, 6));
		}
		if (punishInfoConditionGisVO.getYear() == null || punishInfoConditionGisVO.getYear().length() == 0) {
			punishInfoConditionGisVO.setYear(getDateOfYeaf());
		}
		List<PunishInfoGisVO> list = punishInfoGisVODao.queryCompanyPunishInfo(punishInfoConditionGisVO);
		return list;
		
	}

	/**
	 * 
	 * getDateOfYeaf:TODO 得到当前日期的年份
	 *
	 * @return String
	 */
	private static String getDateOfYeaf() {
		Calendar now = Calendar.getInstance();
		int year = now.get(Calendar.YEAR);
		System.err.println(year);
		return year+"";
	}
	
	/**
	 * queryCompanyPunishRanking:TODO 查询企业违法排名，违法次数最多的排在最前面
	 *
	 * @param punishInfoConditionGisVO
	 * @return List<PunishInfoGisVO>
	 */
	@Override
	public Map<String, Object> queryCompanyPunishRanking(PunishInfoConditionGisVO punishInfoConditionGisVO) {
		String areacode = punishInfoConditionGisVO.getAreacode();
		if(StringUtil.isEmpty(areacode)){
			punishInfoConditionGisVO.setDisposeAreacode("45");
		} else {
			if (!areacode.substring(2, 4).equals("00") && areacode.substring(4, 6).equals("00")) {
				punishInfoConditionGisVO.setDisposeAreacode(areacode.substring(0, 4));
			}
			if (!areacode.substring(2, 4).equals("00") && !areacode.substring(4, 6).equals("00")) {
				punishInfoConditionGisVO.setDisposeAreacode(areacode.substring(0, 6));
			}
		}
		
		if (punishInfoConditionGisVO.getPageNum() == null) {
			punishInfoConditionGisVO.setPageNum(1);
		}
		if (punishInfoConditionGisVO.getPageSize() == null) {
			punishInfoConditionGisVO.setPageSize(20);
		}
		Map<String, Object> map = new HashMap<>();
		PageHelper.startPage(punishInfoConditionGisVO.getPageNum(), punishInfoConditionGisVO.getPageSize());
		List<PunishInfoGisVO> list = punishInfoGisVODao.queryCompanyPunishRanking(punishInfoConditionGisVO);
		PageInfo<PunishInfoGisVO> listData = new PageInfo<>(list, 5);
		String cityName = areaCodeGisDao.queryCityNameByAreacode(punishInfoConditionGisVO.getAreacode());
		map.put("listdata", listData);
		map.put("cityName", cityName);
		return map;
		
	}

	@Override
	public List<PunishInfoGisVO> queryPunishInfoByPscode(PunishInfoConditionGisVO punishInfoConditionGisVO) {
		
		List<PunishInfoGisVO> list = punishInfoGisVODao.queryPunishInfoByPscode(punishInfoConditionGisVO);
		return list;
		
	}
}
